package com.legrandgourmet.android.promocion;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class PremiosActivity extends Activity{
	private TextView TitleTextView;
	  String[] descripcion = {
	            "Premio a la calidad empresarial 2005",
	            "Premio cuchara de oro 2007",
	            "Gorro Condecoraciones Internacionales",
	            "Medallas Del Consejo Iberoamericano",
	            "Certificaciones Internacionales",
	            "IV Premio Iberoamericano a la Excelencia Educativa 2007",
	            "Somos Parte Del Iberoamericano",
	            "Premio Internacional, Calidad Empresarial",
	            "Premio Iberoamericano a la excelencia"
	       };
	  Integer[] pics = {
	  		R.drawable.large1_png,
	  		R.drawable.large2_png,
	  		R.drawable.large3_png,
	  		R.drawable.large4_png,
	  		R.drawable.large5_png,
	  		R.drawable.large6_png,
	  		R.drawable.large7_png,
	  		R.drawable.large8_png,
	  		R.drawable.large9_png
	  };
	ImageView imageView;
	Resources rs;
	
	MenuItem inicio;
	MenuItem carreras;
	MenuItem cursos;
	MenuItem sedes;
	
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_premios); 
        rs = this.getResources();
        Gallery ga = (Gallery)findViewById(R.id.Gallery01);
        ga.setAdapter(new ImageAdapter(this));

        TitleTextView = (TextView)findViewById(R.id.textView1);
        imageView = (ImageView)findViewById(R.id.ImageView01);
        Typeface face=Typeface.createFromAsset(getAssets(), "fonts/Gabrielle.ttf"); 
        TitleTextView.setTypeface(face); 
        ga.setSelection(4);
        TitleTextView.setText(descripcion[4]);
        imageView.setImageResource(pics[4]);
        ga.setOnItemClickListener(new OnItemClickListener() {

		
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				TitleTextView.setText(descripcion[arg2]);
				/*Toast.makeText(getBaseContext(), 
						"You have selected picture " + (arg2+1) + " of Antartica", 
						Toast.LENGTH_SHORT).show();*/
				imageView.setImageResource(pics[arg2]);
				
			}
        	
        });
        
    }
	
	@Override  
    public boolean onCreateOptionsMenu(Menu menu) {
    	inicio = menu.add(rs.getString(R.string.inicio));
    	inicio.setIcon(R.drawable.icono_inicio);
    	
	  	carreras = menu.add(rs.getString(R.string.carreras));
	  	carreras.setIcon(R.drawable.icono_carreras);
	  	
	  	cursos = menu.add(rs.getString(R.string.cursos));
	  	cursos.setIcon(R.drawable.icono_cursos);
	  	
	  	sedes = menu.add(rs.getString(R.string.sedes));
	  	sedes.setIcon(R.drawable.icono_sedes);
	  	
	  	return super.onCreateOptionsMenu(menu); 
    }
	
	@Override 
 	public boolean onOptionsItemSelected(MenuItem item) {
	     	Intent i;
	     	
	     	if(item.equals(inicio)){
	     		i = new Intent(this,DescripcionActivity.class);
		  		startActivity(i);
		  	    finish();
	     	}
	     	
	     	if(item.equals(carreras)){
	     		i = new Intent(this,CarrerasActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	if(item.equals(cursos)){
	     		i = new Intent(this,CursosActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	if(item.equals(sedes)){
	     		i = new Intent(this,SedesActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	return false;
    }
	
	
    
    public class ImageAdapter extends BaseAdapter {

    	private Context ctx;
    	int imageBackground;
    	
    	public ImageAdapter(Context c) {
			ctx = c;
			TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
			imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
			ta.recycle();
		}

		
    	public int getCount() {
    		
    		return pics.length;
    	}

    
    	public Object getItem(int arg0) {
    		
    		return arg0;
    	}

    	
    	public long getItemId(int arg0) {
    		
    		return arg0;
    	}

    	
    	public View getView(int arg0, View arg1, ViewGroup arg2) {
    		ImageView iv = new ImageView(ctx);
    		iv.setImageResource(pics[arg0]);
    		iv.setScaleType(ImageView.ScaleType.FIT_XY);
    		iv.setLayoutParams(new Gallery.LayoutParams(170,170));
    		iv.setBackgroundResource(imageBackground);
    		
    		return iv;
    	}

    }
	
}
